/**
 * v-hasPermi 操作权限处理
 * Copyright (c) 2019 ruoyi
 */

import store from "../store/index";

export default {
  mounted: (el, binding, vnode) => {
    let permissionFlag = binding.value;
    let permissions = store.state.userPermissionArray;
    if (
      permissionFlag &&
      permissionFlag instanceof Array &&
      permissionFlag.length > 0
    ) {
      const hasPermissions = permissions.some((permission) => {
        return (
          permissionFlag === permission || permissionFlag.includes(permission)
        );
      });
      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el);
      }
    } else {
      throw new Error(`请设置操作权限标签值`);
    }
  },
};
